﻿//-----------------------------------------------------------------------
// <copyright file="HyperlinkContext.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.XamlUtility
{
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Navigation;

    /// <summary>
    /// Data to set on a new hyperlink - event handlers
    /// And similar data to use when formatting messages
    /// </summary>
    public class HyperlinkContext
    {
        /// <summary>
        /// Initializes a new instance of the HyperlinkContext class
        /// </summary>
        /// <param name="sitePrefix">the site url prefix</param>
        /// <param name="requestNavigate">the navigate handler</param>
        /// <param name="mouseEnter">the mouse enter handler</param>
        /// <param name="mouseLeave">the mouse leave handler</param>
        public HyperlinkContext(
            string sitePrefix, 
            RequestNavigateEventHandler requestNavigate, 
            MouseEventHandler mouseEnter, 
            MouseEventHandler mouseLeave)
        {
            this.SitePrefix = sitePrefix;

            this.RequestNavigate = requestNavigate;
            this.MouseEnter = mouseEnter;
            this.MouseLeave = mouseLeave;
        }

        /// <summary>
        /// Initializes a new instance of the HyperlinkContext class copying from another
        /// </summary>
        /// <param name="original">the hyperlink context to copy</param>
        public HyperlinkContext(HyperlinkContext original)
        {
            this.SitePrefix = original.SitePrefix;

            this.RequestNavigate = original.RequestNavigate;
            this.MouseEnter = original.MouseEnter;
            this.MouseLeave = original.MouseLeave;
        }

        /// <summary>
        /// Gets the RequestNavigateHandler - called whrn the link is clicked
        /// </summary>
        public RequestNavigateEventHandler RequestNavigate { get; private set; }

        /// <summary>
        /// Gets the MouseEnter handler
        /// </summary>
        public MouseEventHandler MouseEnter { get; private set; }

        /// <summary>
        /// Gets the MouseLeave handler
        /// </summary>
        public MouseEventHandler MouseLeave { get; private set; }

        /// <summary>
        /// Gets or sets the prefix to use for relative Urls
        /// </summary>
        public string SitePrefix { get; set; }

        /// <summary>
        /// Populate event handlers on the hyperlink
        /// </summary>
        /// <param name="link">the link to populate</param>
        public void SetContextOnHyperlink(Hyperlink link)
        {
            if (this.RequestNavigate != null)
            {
                link.RequestNavigate += this.RequestNavigate;
            }

            if (this.MouseEnter != null)
            {
                link.MouseEnter += this.MouseEnter;
            }

            if (this.MouseLeave != null)
            {
                link.MouseLeave += this.MouseLeave;
            }
        }
    }
}
